package com.jk.wh.dao;

import com.jk.*;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.data.elasticsearch.repository.ElasticsearchCrudRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface MovieDao{

    List<MovieBean> queryMovie(@Param("movie") MovieBean movie);
    //查询正在热映的电影
    @Select("select t.*,t.ticketCount*t1.moviePrice money from t_movie t  left join t_movie_cinema t1 on t.movieId=t1.movieId \n" +
            "where t.`status`=1\n" +
            "group by t.movieId order by t.ticketCount*t1.moviePrice desc")
    List<MovieBean> getRadientMovie();
    //查询待上映的电影
    @Select("select * from t_movie t where t.status=2 order by t.filmSchedule")
    List<MovieBean> waitMovie();
    //查询最受期待电影前10
    @Select("select * from t_movie t where status=2 order by t.lookcount desc limit 0,9")
    List<MovieBean> expectMovie();
    //查询前10个高评分电影
    @Select(" select t.*,GROUP_CONCAT(tr.roleName)roleName from t_movie t\n" +
            "        LEFT JOIN t_role_power trp on t.movieId=trp.movieId\n" +
            "        LEFT JOIN  t_role tr on tr.roleId=trp.roleId where t.status =1\n" +
            "        GROUP BY t.movieId ORDER BY movieGrade desc limit 0,9")
    List<MovieBean> getScore();
    //查询所有影院
    @Select("select * from t_cinema")
    List<CinemaBean> queryCinema();
    //查询所有演员
    @Select("select * from t_actor")
    List<ActorBean> queryActor();
    //查询已上映的总条数
    @Select("select count(1) from t_movie where status=1")
    Integer getMovieCount();
    //查询待上映的总条数
    @Select("select count(1) from t_movie where status=2")
    Integer getMovieCount2();
    //查询轮播图
    @Select("select * from t_carousel")
    List<CarouselBean> getCarousel();
    //查询类型表
    @Select("select * from t_movie_type")
    List<MovieTypeBean> getType();
    //查询es条查总条数
    @Select("select count(1) from t_movie where movieName like '%${movieName}%'")
    Integer getMovieCountByStatus(String movieName);
    //查询热播电影
    @Select("select * from t_movie where status=3")
    List<MovieBean> queryHitTv(MovieBean mm);
    //获取票房排行前五名
    @Select("select t.*,sum(t.ticketCount*t1.moviePrice) money from t_movie t  left join t_movie_cinema t1 on t.movieId=t1.movieId where t.status=1 or t.status=3 GROUP BY t.movieId order by  t.ticketCount*t1.moviePrice desc limit 0,4")
    List<MovieBean> getMoney();
    //查询影院
    List<CinemaBean> queryCinemaAll(CinemaBean cc);
    //根据id查询影院
    CinemaBean buyTicketById(Integer cinemaId);
    //根据影院id查询影院对应的电影
    List<MovieBean> queryMovieAllById(Integer cinemaId);
    //根据影院id 电影id查看观影时间
    List<MovieBean> getMovieCinemaById(@Param("cinemaId") Integer cinemaId, @Param("movieId") Integer movieId,@Param("date") String date);
    //根据影院id 电影id查询影院对应的电影
    MovieBean getMovies2(@Param("cinemaId") Integer cinemaId,@Param("movieId") Integer movieId);
    //动态查询排片时间
    List<ProgramBean> getDate(@Param("cinemaId") Integer cinemaId,@Param("movieId") Integer movieId);
    //获取西安的影院
    @Select("select * from t_cinema t where t.cityId=1")
    List<CinemaBean> getCinema();
    //获取西安市的区
   @Select("select t1.addressName,t1.addressId from t_address t, t_address t1 \n" +
           "\t\t\t\twhere t.addressId=t1.pid and t.addressId=1")
    List<AddressBean> getAddressById();
    //查询影厅
    @Select("select * from t_movie_hall t group by t.hallname")
    List<MovieHallBean> getHall();

    //修改座位状态
    @Update("update t_seat set status = 1 where seat_x = #{aChar} and seat_y = #{aChar1} and cinemaId = #{order.cinemaId} and hallId = #{order.hallId} ")
    void updateSeats(@Param("aChar") char aChar, @Param("aChar1")char aChar1, @Param("order")OrderBean orderBean);
}
